home *** CD-ROM | disk | FTP | other *** search
- ===========================================================================
- BBS: The Abacus * HST/DS * Potterville MI
- Date: 03-28-93 (17:22) Number: 37
- From: BOB STOUT Refer#: 34
- To: FRED COLE Recvd: NO
- Subj: FINDING FILE LENGTH Conf: (36) C Language
- ---------------------------------------------------------------------------
- In a message of <Mar 26 20:09>, Fred Cole (1:231/50.4@fidonet.org) writes:
-
- >I have a nasty habit of concatenating to the end of files and not paying
- >attention to any ^Z chars that may be lurking about. Some editors are VERY
- >unforgiving and I don't always remember to check before I save a file. Thank
- >God for Peter Norton! May he live long and prosper. <g>
-
- No need, use this from the next SNIPPETS:
-
- /*
- ** STRIPEOF.C
- **
- ** public domain demo by Bob Stout
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <io.h>
- #include <fcntl.h>
-
- #define BUFSIZE 16384
-
- int main(int argc, char *argv[])
- {
- char *buf;
-
- if (2 > argc)
- {
- puts("Usage: STRIPEOF filename1 [...filenameN]");
- return EXIT_FAILURE;
- }
- if (NULL == (buf = malloc(BUFSIZE)))
- {
- puts("STRIPEOF internal failure");
- return EXIT_FAILURE;
- }
- while (--argc)
- {
- int fd;
- size_t bytes;
- int found = 0;
- long zpos = 0L;
-
- if (-1 == (fd = open(*(++argv), O_RDWR | O_BINARY)))
- {
- printf("Couldn't open %s\n", *argv);
- return EXIT_FAILURE;
- }
- while (0 < (bytes = read(fd, buf, BUFSIZE)))
- {
- int i;
-
- for (i = 0; i < (int)bytes; ++i)
- {
- if (('Z' - 64) == buf[i])
- {
- found = 1;
- zpos += i;
- break;
- }
- }
- if (found)
- break;
- zpos += bytes;
- }
- if (found)
- chsize(fd, zpos);
- }
- return EXIT_SUCCESS;
- }
-
-
- --- QM v1.00
- * Origin: MicroFirm : Down to the C in chips (1:106/2000.6)
- SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
- SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 280/1
- SEEN-BY: 390/1 396/1 5 15 730/6 2270/1 3603/20
-